﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using ClassLibrary;
using ClassLibrary.Configuration.WireCloud;

namespace ConfigGenerator
{
    class WireCloudConfigGenerator
    {
        public WireCloudConfigGenerator(String outputPath)
        {
            var wireCloudConfig = new WireCloudConfig()
                {
                    CloudPort = 9050,
                    Links = new List<Link>() 
                    {
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Client0", PortId = 0},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch0", PortId = 0}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Client2", PortId = 0},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch0", PortId = 1}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Client1", PortId = 0},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch2", PortId = 0}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Client3", PortId = 0},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch2", PortId = 1}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Switch0", PortId = 3},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch1", PortId = 0}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Switch0", PortId = 2},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch3", PortId = 0}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Switch1", PortId = 1},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch2", PortId = 3}
                        },
                        new Link()
                        {
                            EndPoint1 = new Link.EndPoint(){Id = "Switch3", PortId = 1},
                            EndPoint2 = new Link.EndPoint(){Id = "Switch2", PortId = 2}
                        },
                    }
                };

            var writer = new XmlSerializer(typeof(WireCloudConfig));
            using (var file = File.Create(outputPath))
            {
                writer.Serialize(file, wireCloudConfig);
            }

        }
    }
}
